package com.study.designmodes.service.executor.businessTask;

import com.study.designmodes.enums.BusinessCodeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 业务任务执行注册器
 *
 * @author yangyanbin
 * @date 2023/02/01
 * @since 20230201
 */
public class BusinessTaskExecutorRegister {

    /**
     * 执行器容器
     */
    private static final Map<BusinessCodeEnum, BusinessTaskAbstractExecutor> EXECUTOR_MAP = new HashMap<>();

    /**
     * 注册
     *
     * @param businessCodeEnum 类型
     * @param executor         注册执行器
     */
    public static void register(BusinessCodeEnum businessCodeEnum, BusinessTaskAbstractExecutor executor) {
        EXECUTOR_MAP.put(businessCodeEnum, executor);
    }

    /**
     * 查找执行器
     *
     * @param businessCodeEnum 类型
     * @return 返回执行器
     */
    public static BusinessTaskAbstractExecutor findByType(BusinessCodeEnum businessCodeEnum) {
        return EXECUTOR_MAP.get(businessCodeEnum);
    }
}
